import 'package:bwt_ad_flutter/BwtAdCore.dart';
import 'package:bwt_ad_flutter/ad/loader/BwtAdLoader.dart';
import 'package:bwt_ad_flutter/ad/widget/bannerWidget/BwtBannerAd.dart';
import 'package:bwt_ad_flutter/ad/widget/bannerWidget/BwtBannerWidget.dart';
import 'package:flutter/material.dart';

class BwtBannerAdLoader extends BwtAdLoader<BwtBannerAd> {
  /// 加载广告
  loadAd({
    required String posId,
    required double adWidth,
    required double adHeight,
    bool? showClose = false,
  }) {
    if (adWidth <= 0 || adHeight <= 0) {
      debugPrint("广告宽度和高度必须大于0!");
      throw ArgumentError("广告宽度和高度必须大于0");
    }
    load(
      posId: posId,
      methodName: BwtAdCore.methodLoadBannerAd,
      arguments: {
        BwtAdCore.keyAdWidth: adWidth,
        BwtAdCore.keyAdHeight: adHeight,
        BwtAdCore.keyAdShowClose: showClose
      },
    );
  }

  @override
  onAdLoadCallback(BwtBannerAd bwtAd) {
    bwtAd.bannerAdview = BwtBannerWidget(
      bwtBannerAd: bwtAd,
      viewType: BwtAdCore.viewTypeBwtBannerAd,
    );
    return super.onAdLoadCallback(bwtAd);
  }

  @override
  BwtBannerAd createBwtAd(
      {required String adId, required Map<String, dynamic>? arguments}) {
    return BwtBannerAd(
      adId: adId,
      adLoaderId: adLoaderId,
      adWidth: arguments?[BwtAdCore.keyAdWidth] ?? double.infinity,
      adHeight: arguments?[BwtAdCore.keyAdHeight] ?? double.infinity,
    );
  }
}
